package cn.tedu.visualization.controller;

import cn.tedu.common.web.JsonResult;
import cn.tedu.visualization.pojo.entity.PieDemo;
import cn.tedu.visualization.pojo.entity.PieDemo1;
import cn.tedu.visualization.service.ITestPieService;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("test/")
public class TestPieController {

    @Autowired
    private ITestPieService service;

    @PostMapping("/testPie")
    public String testPie(Model model) {
        return "/test/TestPie";
    }

    @PostMapping("/showPie")
    @ApiOperation(value = "测试")
    public JsonResult gotoIndex() {
        List<PieDemo> newPieDemos = service.countUser();
       /* List<PieDemo> pieDemos = service.countUser();
        List<PieDemo> newPieDemos = new ArrayList<>();
        for (int i = 1; i <= 12; i++) {
            PieDemo pd = new PieDemo();
            pd.setX(i+"月");
            pd.setY(0);
            for (PieDemo p : pieDemos) {
                if (("0"+i).equals(p.getX())||String.valueOf(i).equals(p.getX())){
                  pd.setY(p.getY());
                }
            }
            newPieDemos.add(pd);
        }*/
        return JsonResult.ok(newPieDemos);
    }

    @PostMapping("/showPie1")
    @ApiOperation(value = "测试1")
    public JsonResult gotoIndex1() {
        List<PieDemo1> newPieDemos = service.countOrder();
       /* List<PieDemo> pieDemos = service.countUser();
        List<PieDemo> newPieDemos = new ArrayList<>();
        for (int i = 1; i <= 12; i++) {
            PieDemo pd = new PieDemo();
            pd.setX(i+"月");
            pd.setY(0);
            for (PieDemo p : pieDemos) {
                if (("0"+i).equals(p.getX())||String.valueOf(i).equals(p.getX())){
                  pd.setY(p.getY());
                }
            }
            newPieDemos.add(pd);
        }*/
        return JsonResult.ok(newPieDemos);
    }


   /* @PostMapping("/showPie1")
    public List<PieDemo> gotoIndex1() {
        ArrayList<PieDemo> lineDemos = new ArrayList<>();
//        Random r = new Random();
        for (int i = 1; i <= 12; i++) {
            PieDemo pd = new PieDemo();
            pd.setX(i + "月");
//            pd.setY(r.nextInt(100));
            int count = service.countOrder();
            pd.setY(count);
            lineDemos.add(pd);
        }
        return lineDemos;
    }*/
 /*   @ResponseBody
    @RequestMapping("/showPie2")
    public List<PieDemo> gotoIndex2(){
        ArrayList<PieDemo> lineDemos=new ArrayList<>();

        Random r = new Random();
        for(int i=1;i<=12;i++){
            PieDemo pd=new PieDemo();
            pd.setX(i+"月");
            pd.setY(r.nextInt(100));
            lineDemos.add(pd);
        }
        return lineDemos;
    }*/
}